﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectStorageDB;
using ProjectStorageLib;
using ProjectStorageLib.Practices;

public partial class controls_PracticeCoverage : System.Web.UI.UserControl
{
    public List<decimal> selectedPractices { get; set; }
    public List<AgilePrinciples> coveredPrinciples { get; set; }
    public List<AgileValues> coveredValues { get; set; }
    public List<ProcessActivities> coveredActivities { get; set; }
    public List<ProcessDisciplines> coveredDisciplines { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            grdPrinciplesCoverage.Visible = false;
            grdValuesCoverage.Visible = false;
            grdActivitiesCoverage.Visible = false;
            grdDisciplinesCoverage.Visible = false;
        }
                
    }

    public bool IsPrincipleCovered(decimal PrincipleID)
    {
        if (coveredPrinciples != null)
            return ((from c in coveredPrinciples where c.ID == PrincipleID select c).Count() > 0);
        else
            return false;
    }

    public bool IsValueCovered(decimal ValueID)
    {
        if (coveredValues != null)
            return ((from c in coveredValues where c.ID == ValueID select c).Count() > 0);
        else
            return false;
    }

    public bool IsActivityCovered(decimal ActivityID)
    {
        if (coveredActivities != null)
            return ((from c in coveredActivities where c.ID == ActivityID select c).Count() > 0);
        else
            return false;
    }

    public bool IsDisciplineCovered(decimal DisciplineID)
    {
        if (coveredDisciplines != null)
            return ((from c in coveredDisciplines where c.ID == DisciplineID select c).Count() > 0);
        else
            return false;
    }

    protected void ShowCoverage(object sender, EventArgs e)
    {
        if (selectedPractices != null)
            selectedPractices.Clear();
        else
            selectedPractices = new List<decimal>();

        for (int i = 0; i < chlPractices.Items.Count; i++)
        {
            if (chlPractices.Items[i].Selected)
                selectedPractices.Add(Convert.ToDecimal(chlPractices.Items[i].Value));
        }

        PracticeManager prmanager = new PracticeManager();
        coveredPrinciples = prmanager.GetPrinciplesCoverage(selectedPractices);
        coveredValues = prmanager.GetValuesCoverage(selectedPractices);
        coveredActivities = prmanager.GetActivitiesCoverage(selectedPractices);
        coveredDisciplines = prmanager.GetDisciplinesCoverage(selectedPractices);

        grdPrinciplesCoverage.Visible = true;
        grdValuesCoverage.Visible = true;
        grdActivitiesCoverage.Visible = true;
        grdDisciplinesCoverage.Visible = true;

        grdPrinciplesCoverage.DataBind();
        grdValuesCoverage.DataBind();
        grdActivitiesCoverage.DataBind();
        grdDisciplinesCoverage.DataBind();

    }
}